package com.da.javalog.template.core;

import com.da.javalog.template.name.BaseNameTemplate;
import com.da.javalog.template.type.BaseTypeTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @description 扫描模板注解，统一进行管理
 */
@Component
@Slf4j
public class TemplateBeanPostProcessor implements BeanPostProcessor {
    /**
     * Bean 实例化之前进行的处理
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    /**
     * Bean 实例化之后进行的处理
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof BaseNameTemplate) {
            TemplateManager.process(bean, beanName);
        }
        if (bean instanceof BaseTypeTemplate) {
            TemplateManager2.process(bean, beanName);
        }
        return bean;
    }
}